package com.jian.exceldaoru.controller;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lijian on 2020/10/19 15:49
 */
public class StringUtil {
    public static List<String> splitStringBy(String data){
        List<String> result = new ArrayList<>();
        if(!data.isEmpty()){
            result = splitStringBy(data,":");
        }
        return result;
    }
    public static List<String> splitStringBy(String data,String pattern){
        List<String> result = new ArrayList<>();
        if(!data.isEmpty()&&!pattern.isEmpty()){
            String[] data1 = data.split(pattern);
            if(data1.length>0){
                for(int i=0;i<data1.length;i++){
                    result.add(data1[i]);
                }
            }
        }
        return result;
    }
    public static List<String> splitString(String data,String pattern){
        List<String> result = new ArrayList<>();
        if(!data.isEmpty()&&!pattern.isEmpty()){
            String[] data1 = data.split(pattern,-1);
            if(data1.length>0){
                for(int i=0;i<data1.length;i++){
                    result.add(data1[i]);
                }
            }
        }
        return result;
    }

    public static List<String> subStringBy(String data){
        int zhongwen = data.indexOf("：");
        int english = data.indexOf(":");
        List<String> result = new ArrayList<>();
        if(!data.isEmpty()){
            if(zhongwen!=-1&&english!=-1){
                if(zhongwen<english){
                    result = subStringBy(data,"：");
                }else{
                    result = subStringBy(data,":");
                }
            }else if(english==-1){
                result = subStringBy(data,"：");
            }else if(zhongwen==-1){
                result = subStringBy(data,":");
            }
        }
        return result;
    }
    public static List<String> subStringBy(String data,String pattern){
        List<String> result = new ArrayList<>();
        if(!data.isEmpty()&&!pattern.isEmpty()) {
            String str = data.substring(0, data.indexOf(pattern));
            String str1 = data.substring(data.indexOf(pattern)+1,data.length());
            result.add(str);
            result.add(str1);
        }
        return result;
    }
}
